define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/orderitemck/index' + location.search,
                    add_url: 'crm/orderitemck/add',
                    edit_url: 'crm/orderitemck/edit',
                    del_url: 'crm/orderitemck/del',
                    multi_url: 'crm/orderitemck/multi',
                    import_url: 'crm/orderitemck/import',
                    table: 'crm_orderitemck',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'goods_item_id', title: __('Goods_item_id')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'num', title: __('Num')},
                        {field: 'danwei', title: __('Danwei'), operate: 'LIKE'},
                        {field: 's_day', title: __('S_day'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'b_num', title: __('B_num')},
                        {field: 'e_day', title: __('E_day'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'youhui_price', title: __('Youhui_price'), operate:'BETWEEN'},
                        {field: 'zong_price', title: __('Zong_price'), operate:'BETWEEN'},
                        {field: 'emo', title: __('Emo'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'orderck.order_no', title: __('Orderck.order_no'), operate: 'LIKE'},
                        {field: 'goods.goods_name', title: __('Goods.goods_name'), operate: 'LIKE'},
                        {field: 'spec.spec_name', title: __('Spec.spec_name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
